import { Injectable } from '@angular/core'
import { HttpClient } from '@angular/common/http'
import { Observable } from 'rxjs'

import { COMB_URL } from 'app/utils/contraints'
import { DashboardService } from './dashboard.abstract.service'
import { ITaskQueryParams, ITaskPagination, Task, ETaskCategory, IEnrolReq, IEnrolRes } from '@shared/interfaces/task'
import { preProcessParams, encodeParams } from '@shared/decorators'
import { IAuditProcessReq } from '@shared/interfaces/audit'


@Injectable()
export class DashboardAlinterService implements DashboardService {

  constructor(
    private http: HttpClient,
  ) { }

  @preProcessParams()
  @encodeParams()
  getList(params: ITaskQueryParams, type: ETaskCategory, str?: string): Observable<ITaskPagination> {
    const url = `${COMB_URL}/camel/jobs/${type}?${str}`
    return this.http.get<ITaskPagination>(url)
  }

  getOne(jobID: string): Observable<Task> {
    const url = `${COMB_URL}/camel/job/${jobID}`
    return this.http.get<Task>(url)
  }

  resolve(data: IAuditProcessReq): Observable<boolean> {
    const url = `${COMB_URL}/camel/audit/resolve`
    return this.http.post<boolean>(url, data)
  }

  reject(data: IAuditProcessReq): Observable<boolean> {
    const url = `${COMB_URL}/camel/audit/reject`
    return this.http.post<boolean>(url, data)
  }

  submit(token: string): Observable<boolean> {
    const url = `${COMB_URL}/camel/audit/submission/${token}`
    return this.http.post<boolean>(url, {})
  }

  enrollment(data: IEnrolReq): Observable<IEnrolRes> {
    const url = `${COMB_URL}/camel/audit/enrollment`
    return this.http.post<IEnrolRes>(url, data)
  }
}
